let app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    projectId: undefined,
    tabsIndex: 1,
    yearList: [],
    searchYear: undefined,
    searchYearIndex: undefined,
    tabsIndexAssess: 2, // 领导点评小tab，1 当天，2 前期
    tabsIndexFigure: 1,  // 形象进度小tab，1 领导联系项目，2 项目形象展示
    content: '',  //领导点评 - 点评内容
    images: [],
    pro_id: '',
    updatefield: '',
    updatevalue: '',
    id: '',
    leading_cadre: 0,
    diffiValue: '', //推进困难
    libraryTab: 0,
    time1: '请选择日期',  //上会时间
    time2: '请选择日期',  //签约时间
    remark: '',  //审核情况
    radio: 1,  //是否入统计库启报投资，1是 2否
    year: '2021',  //截至xxxx年
    year_val: '',  //截至xxxx年的投资金额
    january_february: '',
    march: '',
    april: '',
    may: '',
    june: '',
    july: '',
    august: '',
    september: '',
    october: '',
    november: '',
    december: '',
    invested: 0,  //已完成投资
    percentage: 0,  //已完成投资占比
    investment: 0,  //总投资
    yearEnd: '',
    selectorVal: [
      {
        value: 1,
        name: '是'
      },
      {
        value: 2,
        name: '否'
      }
    ],
    projectStatus: [
      {
        value: 0,
        name: '基础开工'
      },
      {
        value: 1,
        name: '已竣工'
      },
      {
        value: 2,
        name: '主体开工'
      },
      {
        value: 3,
        name: '已终止'
      }
    ],
    condition_val: [
      {
        value: 1,
        name: '运行正常企业'
      },
      {
        value: 2,
        name: '一般困难企业'
      },
      {
        value: 3,
        name: '特别困难企业'
      },
      {
        value: 4,
        name: '停产企业'
      }
    ],
    cultivation: [
      {
        value: 1,
        name: '计划年度进规企业'
      },
      {
        value: 2,
        name: '计划月度进规企业'
      },
    ],
    quarterKey: 1,
    quarter: [
      { id: 1, title: "上半年" },
      { id: 2, title: "下半年" }
    ],
    monthList: [],
    projectList: [],
    lastFigure: '',
    plan_category: [
      { value: 1, name: "政府投资" },
      { value: 2, name: "产业类" }
    ],
    start_status: [
      { value: 1, name: "待开工" },
      { value: 2, name: "已开工" },
      { value: 3, name: "已逾期" },
      { value: 4, name: "已终止" }
    ],
    project_status: [
      { value: 0, name: "正常" },
      { value: 1, name: "逾期" },
      { value: 2, name: "已完工" },
      { value: 3, name: "无法推进" }
    ],
    warehousing: [
      { value: 1, name: "待入库" },
      { value: 2, name: "已入库" },
    ],
    reply: [
      { value: 1, name: "已启报" },
      { value: 2, name: "已报竭" },
    ],
    operation: [
      { value: 1, name: "正常" },
      { value: 2, name: "异常" },
    ],
    pro_type: [],
    IndustrialChain: [], //所属产业 
    nature: ["新建", "改建", "扩建", "迁建"],
    loading: false,
    figureList: [], //进展情况列表
    overdueList: [], //逾期原因
    time: '',
    type_id: 0
  },


  makePhoneCall:function(e){
    var phoneNumber = app.selectPhoneNumber(e.currentTarget.dataset.val);
    wx.makePhoneCall({
      phoneNumber:phoneNumber //仅为示例，并非真实的电话号码
    })
  },

  //删除图片
  delImage: function (e) {
    var index = e.currentTarget.dataset.v;
    var images = this.data.images;
    images.splice(index, 1);
    this.setData({ images: images });
  },

  //更新计划完成时间
  bindTimeChange: function (e) {
    this.setData({
      time: e.detail.value, type_id: e.currentTarget.dataset.index.id
    });
    this.createPlans();
  },

  //更新计划完成时间
  createPlans() {
    var params = { pro_id: this.data.projectId, type_id: this.data.type_id, time: this.data.time };
    app.request('post', '/api/advance/createPlan', params).then(res => {
      app.showSuccessToast('提交成功');
      this.advanceApi();
    }).catch(err => console.log(err));
  },

  //进展情况添加入口
  progressCreate: function () {
    var basic = this.data.basic;
    var sign = basic.sign;
    var library = basic.library;
    switch (library) {
      case '1':
        wx.navigateTo({
          url: `/pages/progressCreate/progressCreate?proId=${this.data.projectId}&sign=${sign}`,
        });
        break;
      case '6':
        wx.navigateTo({
          url: `/pages/progressCreate/progressCreate?proId=${this.data.projectId}&enterprise=${basic.enterprise_v}`,
        });
        break;
      default:
        wx.navigateTo({
          url: `/pages/progressCreate/progressCreate?proId=${this.data.projectId}&library=${library}`,
        });
        break;
    }


  },

  //逾期说明入口
  overdueCreate: function (e) {
    var type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: `/pages/overdueCreate/overdueCreate?proId=${this.data.projectId}&type=${type}`,
    });
  },

  publicChange(e) {
    var field = e.currentTarget.dataset.updatefield;
    if (field == "project_status") {
      var start_status = this.data.project_status;
      var updatetime = start_status[e.detail.value].value;
    }

    if (field == "start_status") {
      var start_status = this.data.start_status;
      var updatetime = start_status[e.detail.value].value;
    }

    if (field == "project_type") {
      var start_status = this.data.pro_type;
      var updatetime = start_status[e.detail.value].value;
    }

    if (field == "IndustrialChain") {
      var start_status = this.data.IndustrialChain;
      var updatetime = start_status[e.detail.value].value;
    }

    if (field == "warehousing") {
      var start_status = this.data.warehousing;
      var updatetime = start_status[e.detail.value].value;
    }

    if (field == "reply") {
      var start_status = this.data.reply;
      var updatetime = start_status[e.detail.value].value;
    }

    if (field == "operation") {
      var start_status = this.data.operation;
      var updatetime = start_status[e.detail.value].value;
    }

    if (field == "nature") {
      var nature = this.data.nature;
      var updatetime = nature[e.detail.value];
    }

    let params = {
      id: e.currentTarget.dataset.id,
      updatefield: e.currentTarget.dataset.updatefield,
      updatetime: updatetime,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
    }).catch(err => console.log(err));
  },

  //获取逾期列表
  overdueListApi: function (type) {
    let params = {
      id: this.data.projectId, type: type
    };
    app.request('post', '/api/Project/overdueList', params).then(res => {
      this.setData({
        overdueList: res.data.data.list
      });
    }).catch(err => console.log(err));
  },

  //获取进展列表
  progressListApi: function () {
    let params = {
      id: this.data.projectId,
    };
    app.request('post', '/api/Project/progressList', params).then(res => {
      this.setData({
        figureList: res.data.data.list
      });
    }).catch(err => console.log(err));
  },

  //跳转进展情况详情
  progressDetail: function (e) {
    wx.navigateTo({
      url: `/pages/progressCreate/progressDetail?id=` + e.currentTarget.dataset.id,
    });
  },

  //查询计划进展
  advanceApi: function () {
    let params = {
      id: this.data.projectId,
    };
    app.request('post', '/api/Advance/problemTypeApi', params).then(res => {
      this.setData({
        projectList: res.data.data
      });
    }).catch(err => console.log(err));
  },


  //季度选择
  quarterChange: function (e) {
    this.setData({ quarterKey: e.currentTarget.dataset.val });
    this.monthTable();
    this.advanceApi();
  },

  //年份选择
  yearChange: function (e) {
    this.setData({ yearEnd: e.detail.value });
    this.monthTable();
    this.advanceApi();
  },

  /** 跳转 - 编辑推进计划 */
  goAdvance(e) {
    var procedure = e.currentTarget.dataset.val;
    var year = this.data.yearEnd;
    var month = e.currentTarget.dataset.month;
    var pro_id = this.data.projectId;
    wx.navigateTo({
      url: `/pages/advance/advance?id=${pro_id}&procedure=${procedure}&year=${year}&month=${month}`,
    });
  },

  //月份
  monthTable: function () {
    var quarterKey = this.data.quarterKey;
    var topData = [
      { id: 1, title: "1月", status: "" },
      { id: 2, title: "2月", status: "" },
      { id: 3, title: "3月", status: "" },
      { id: 4, title: "4月", status: "" },
      { id: 5, title: "5月", status: "" },
      { id: 6, title: "6月", status: "" }
    ];

    var bottomData = [
      { id: 7, title: "7月", status: "" },
      { id: 8, title: "8月", status: "" },
      { id: 9, title: "9月", status: "" },
      { id: 10, title: "10月", status: "" },
      { id: 11, title: "11月", status: "" },
      { id: 12, title: "12月", status: "" }
    ];

    if (quarterKey == 1) {
      var monthData = topData;
    } else {
      var monthData = bottomData;
    }
    this.setData({ monthList: monthData });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.setData({ projectId: options.id });
    if (options.tabsIndex != undefined) {
      this.setData({
        tabsIndex: options.tabsIndex
      });
    }

    let now = new Date();
    let month = now.getMonth() < 9 ? ('0' + (now.getMonth() + 1)) : now.getMonth();
    let date = now.getDate() < 10 ? ('0' + now.getDate()) : now.getDate();
    let hour = now.getHours() < 10 ? ('0' + now.getHours()) : now.getHours();
    let minute = now.getMinutes() < 10 ? ('0' + now.getMinutes()) : now.getMinutes();
    this.setData({ projectId: options.id, now: `${now.getFullYear()}-${month}-${date} ${hour}:${minute}`, searchYear: now.getFullYear(), libraryTab: options.libraryTab, proId: options.id, yearEnd: new Date().getFullYear() });
    // this.getBasic();
    this.monthTable();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    if (this.data.tabsIndex == 1) {
      this.getBasic();
    }
    if (this.data.tabsIndex == 2) {
      if (this.data.libraryTab == 2 || this.data.libraryTab == 4) {
        this.advanceApi();
      }
    }
    if (this.data.tabsIndex == 3) {
      this.getAssess();
    }
    if (this.data.tabsIndex == 4) {
      this.getFigure();
    }
    if (this.data.tabsIndex == 5) {
      this.fixedDetail();
    }
    if (this.data.tabsIndex == 6) {
      this.progressListApi();
    }
    if (this.data.tabsIndex == 7) {
      this.overdueListApi(3);
    }
    if (this.data.tabsIndex == 8) {
      this.overdueListApi(4);
    }

  },

  /** 大tab切换 */
  onTab(e) {
    this.setData({ tabsIndex: e.currentTarget.dataset.index });
    if (e.currentTarget.dataset.index == 1) {
      this.getBasic();
    }
    if (e.currentTarget.dataset.index == 2) {
      if (this.data.libraryTab == 2 || this.data.libraryTab == 4 || this.data.libraryTab == 3) {
        this.advanceApi();
      }
    }
    if (e.currentTarget.dataset.index == 4) {
      this.getFigure();
    }
    if (e.currentTarget.dataset.index == 3) {
      this.getAssess();
    }
    if (e.currentTarget.dataset.index == 5) {
      this.fixedDetail();
    }
    if (e.currentTarget.dataset.index == 6) {
      this.progressListApi();
    }
    if (e.currentTarget.dataset.index == 7) {
      this.overdueListApi(3);
    }
    if (e.currentTarget.dataset.index == 8) {
      this.overdueListApi(4);
    }
  },

  previewImg2: function (e) {
    let that = this;
    let figureList = that.data.images;
    wx.previewImage({
      current: e.currentTarget.dataset.src,   //当前图片地址
      urls: figureList,        //所有要预览的图片的地址集合 数组形式
    });
  },

  previewImg1: function (e) {
    let that = this;
    var figureList = e.currentTarget.dataset.v;
    wx.previewImage({
      current: e.currentTarget.dataset.src,   //当前图片地址
      urls: figureList,        //所有要预览的图片的地址集合 数组形式
    });
  },


  previewImg: function (e) {
    let that = this;
    wx.previewImage({
      current: e.currentTarget.dataset.src,   //当前图片地址
      urls: that.data.figureList[e.currentTarget.dataset.id].images,        //所有要预览的图片的地址集合 数组形式
    })
  },

  /** 领导点评 小tab切换 */
  onTabAssess(e) {
    this.setData({ tabsIndexAssess: e.currentTarget.dataset.index });
    if (e.currentTarget.dataset.index == 2) this.getAssess();
  },

  /** 形象进度 小tab切换 */
  onTabFigure(e) {
    this.setData({ tabsIndexFigure: e.currentTarget.dataset.index });
  },

  //更新计划类别
  planChange(e) {
    var plan_category = this.data.plan_category;
    var updatetime = plan_category[e.detail.value].value;
    let params = {
      id: e.currentTarget.dataset.id,
      updatefield: e.currentTarget.dataset.updatefield,
      updatetime: updatetime,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
      this.advanceApi();
    }).catch(err => console.log(err));
  },

  bindDateChange2(e) {
    var projectStatus = this.data.projectStatus;
    var updatetime = projectStatus[e.detail.value].value;
    let params = {
      id: e.currentTarget.dataset.id,
      updatefield: e.currentTarget.dataset.updatefield,
      updatetime: updatetime,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
    }).catch(err => console.log(err));
  },

  bindDateChange1(e) {

    var selectorVal = this.data.selectorVal;
    var updatetime = selectorVal[e.detail.value].value;
    let params = {
      id: e.currentTarget.dataset.id,
      updatefield: e.currentTarget.dataset.updatefield,
      updatetime: updatetime,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
    }).catch(err => console.log(err));

  },

  //更新计划开工时间
  bindDateChange(e) {
    let params = {
      id: e.currentTarget.dataset.id,
      updatefield: e.currentTarget.dataset.updatefield,
      updatetime: e.detail.value,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
    }).catch(err => console.log(err));

  },

  /** 基本信息 - 修改 推进困难 */
  onUpdateDiffi(e) {
    this.setData({ pro_id: e.currentTarget.dataset.proid, diffiValue: this.data.basic.difficulty });
    this.diffiPopup.showPopup();
  },

  /** 基本信息 - 推进困难 - 弹出层关闭*/
  onDiffiClose() {
    this.diffiPopup.hidePopup();
  },


  /** 基本信息 - 推进困难 - 弹出层提交*/
  onDiffiSubmit(e) {
    let params = {
      id: this.data.pro_id,
      updatefield: 'difficulty',
      updatetime: this.data.diffiValue,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
    }).catch(err => console.log(err));
    this.diffiPopup.hidePopup();
  },

  /** 基本信息 - 推进困难 - 弹出层输入*/
  onDiffiInput(e) {
    this.setData({ diffiValue: e.detail });
  },

  publicShowPopup(e) {
    this.setData({ pro_id: e.currentTarget.dataset.proid, publicValue: e.currentTarget.dataset.v, newField: e.currentTarget.dataset.field });
    // this.setData({ pro_id: e.currentTarget.dataset.proid, diffiValue: this.data.basic.difficulty});
    this.publicPopup.showPopup();
  },

  publicClose() {
    console.log('关闭');
    this.publicPopup.hidePopup();
  },

  /** 基本信息 - 修改 推进困难 */
  publicSubmit(e) {
    let params = {
      id: this.data.pro_id,
      updatefield: this.data.newField,
      updatetime: this.data.publicValue,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
    }).catch(err => console.log(err));
    this.publicPopup.hidePopup();
  },

  publicInput(e) {
    this.setData({ publicValue: e.detail });
  },

  /** 跳转 - 固投情况 */
  goFixed() {
    wx.navigateTo({
      url: `/pages/fixed/fixed?proId=${this.data.projectId}`,
    });
  },

  //更新推进进度
  onProgress(e) {
    let pro_id = e.currentTarget.dataset.proid;
    let updatefield = e.currentTarget.dataset.updatefield;
    let id = e.currentTarget.dataset.id;
    let updatevalue = e.currentTarget.dataset.updatevalue;
    this.setData({
      pro_id: pro_id,
      updatefield: updatefield,
      updatevalue: updatevalue,
      id: id,
    })
    this.popup.showPopup();
  },

  //接收组件传过来的值
  get_emit: function (e) {
    this.setData({
      updatevalue: e.detail
    })
  },

  //取消事件
  _error() {
    this.popup.hidePopup();
  },
  //确认事件
  _success(e) {
    let params = {
      pro_id: this.data.pro_id,
      updatefield: this.data.updatefield,
      updatevalue: this.data.updatevalue,
      id: this.data.id
    };


    app.request('post', '/api/Project/doplan', params).then(res => {
      this.getProgress();
    }).catch(err => console.log(err));
    console.log(this.data.textareahTML);
    this.popup.hidePopup();
  },



  /** 领导点评 - 当天 - 选择上传图片 */
  onChoosePic() {
    let that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        let tempFilePaths = res.tempFilePaths;
        wx.uploadFile({
          url: `${app.globalData.rootUrl}/api/upload/upload`,
          filePath: tempFilePaths[0],
          name: 'file',
          formData: { 'appid': app.appid },
          success: res => {
            let response = JSON.parse(res.data);
            if (res.statusCode == 200) {
              if (response.code == 0) {
                let images = that.data.images;
                images.push(response.thumb);
                that.setData({ images });
              } else {
                app.showFailToast(response.msg);
              }
            } else app.showFailToast('网络错误，请稍后再试');
          }
        });
      }
    })
  },

  /** 领导点评 - 当天 - 输入点评内容 */
  inputArea1(e) {
    this.setData({ content: e.detail.value });
  },

  /** 领导点评 - 获取当前点评列表 */
  getAssess() {
    app.request('post', '/api/Project/pro_comment', { id: this.data.projectId }).then(res => {
      let assessList = res.data.list;
      if (!Array.isArray(assessList)) return false;
      assessList.forEach(item => {
        if (item.reply_type == 2) item.isShow = false;
      });
      this.setData({ assessList });
    }).catch(err => console.log(err));
  },
  clickReply(e) {
    wx.navigateTo({ url: `/pages/messageReply/reply?id=${e.currentTarget.dataset.id}` });
  },

  clickLookReply(e) {
    let i = e.currentTarget.dataset.index;
    let list = this.data.assessList;
    list[i].isShow = !list[i].isShow;
    this.setData({ assessList: list });
  },

  /** 领导点评 - 重置 */
  onRest() {
    this.setData({ content: '', images: [] });
  },

  /** 领导点评 - 提交 */
  onSubmit() {
    if (this.data.content == '') {
      app.showFailToast('请填写点评内容');
      return false;
    }
    let params = {
      pro_id: this.data.projectId,
      content: this.data.content,
      images: this.data.images.join(';')
    };
    // console.log(params)
    // this.setData({ loading: true });
    app.request('post', '/api/Project/commentApi', params)
      .then(res => {
        app.showSuccessToast('发布成功');
        this.setData({ content: '' });
        setTimeout(() => {
          this.setData({ tabsIndexAssess: 2});
          this.getAssess();
        }, 1500);
      })
      .catch(err => console.log(err));
  },

  /** 获取 基本信息 */
  getBasic() {
    app.request('post', '/api/Project/project_detail', { id: this.data.projectId })
      .then(res => {
        this.setData({ basic: res.data.detail, pro_type: res.data.pro_type, IndustrialChain: res.data.IndustrialChain });
        wx.setNavigationBarTitle({ title: res.data.detail.title });
      })
      .catch(err => console.log(err));
  },

  /** 获取 推进进度 */
  getProgress() {
    let params = {
      id: this.data.projectId,
      year: this.data.searchYear
    };
    app.request('post', '/api/Project/pro_plan', params).then(res => {
      this.setData({ progressList: res.data.list, yearList: res.data.year, leading_cadre: res.data.leading_cadre });
      // this.setData({ progressList: res.data.list, yearList: [2016,2017,2018,2019,2020,2021,2022,2023] });
      let index = this.data.yearList.indexOf(this.data.searchYear);
      if (index >= 3) {
        this.setData({ translateX: (3 - index) * 90, searchYearIndex: index });
      }
    }).catch(err => console.log(err));
  },

  /** 形象进度 - 获取列表 */
  getFigure() {
    app.request('post', '/api/Project/pro_figure', { id: this.data.projectId }).then(res => {
      if (res.data.lastFigure != null) {
        this.setData({ lastFigure: res.data.lastFigure });
      }

      this.setData({ figureList: res.data.list });
    }).catch(err => console.log(err));
  },

  /** 形象进度 - 添加 */
  figureCreate() {
    var libraryTab = this.data.libraryTab
    if (libraryTab == 6) {
      wx.navigateTo({ url: `/pages/visitor/visitor?id=${this.data.projectId}` });
    } else {
      wx.navigateTo({ url: `/pages/figureCreate/figureCreate?id=${this.data.projectId}` });
    }
  },

  /** 逾期说明 - 添加 */
  beoverdue() {
    wx.navigateTo({ url: `/pages/beoverdue/beoverdue?id=${this.data.projectId}` });
  },

  /** 推进进度 - 添加 */
  planCreate() {
    wx.navigateTo({ url: `/pages/planCreate/planCreate?id=${this.data.projectId}` });
  },

  /** 推进进度 - 点击箭头自动切换年份查询 */
  clickArrow(e) {
    let index = this.data.searchYearIndex;
    if ('left' == e.currentTarget.dataset.arrow) index == 0 ? index = 0 : index -= 1;
    if ('right' == e.currentTarget.dataset.arrow) {
      let length = this.data.yearList.length - 1;
      index < length ? index += 1 : index = length;
    }
    this.setData({ searchYear: this.data.yearList[index], searchYearIndex: index });
    this.getProgress();
  },

  /** 推进进度 - 点击某个年份查询 */
  clickYear(e) {
    let year = e.currentTarget.dataset.year;
    let index = e.currentTarget.dataset.index;
    this.setData({ searchYear: year, searchYearIndex: index });
    this.getProgress();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //获得popup组件
    this.popup = this.selectComponent('#popup');
    this.diffiPopup = this.selectComponent('#diffiPopup');

    this.publicPopup = this.selectComponent('#publicPopup')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //查看详细进度
  planList: function () {
    var projectId = this.data.projectId;
    var searchYear = this.data.searchYear;
    wx.navigateTo({ url: `/pages/planList/planList?id=` + projectId + '&year=' + searchYear });
  },

  //固投情况
  fixedDetail: function () {
    app.request('post', '/api/Project/fixedDetail', { pro_id: this.data.proId }).then(res => {
      this.setData({ invested: res.data.invested, percentage: res.data.percentage, investment: parseFloat(res.data.investment) });
      if (res.data.detail != '') {
        this.setData({
          time1: res.data.detail.meeting,
          time2: res.data.detail.signing_time,
          remark: res.data.detail.remark,
          radio: res.data.detail.is_ok,
          year: res.data.detail.year,
          year_val: res.data.detail.year_val,
          january_february: res.data.detail.january_february,
          march: res.data.detail.march,
          april: res.data.detail.april,
          may: res.data.detail.may,
          june: res.data.detail.june,
          july: res.data.detail.july,
          august: res.data.detail.august,
          september: res.data.detail.september,
          october: res.data.detail.october,
          november: res.data.detail.november,
          december: res.data.detail.december
        });
      }
      wx.hideLoading();
    }).catch(err => console.log(err));
  },

  /** 上会时间 */
  changeDate1(e) {
    this.setData({ time1: e.detail.value });
  },

  /** 签约时间 */
  changeDate2(e) {
    this.setData({ time2: e.detail.value });
  },

  /** 截至年份 */
  changeDate3(e) {
    this.setData({ year: e.detail.value });
  },

  /** 审核情况 */
  inputArea(e) {
    this.setData({ remark: e.detail.value });
  },

  /** 取消 */
  onCancel() {
    wx.navigateBack();
  },

  /** 统计库 - 投资金额 输入 */
  onInput(e) {
    let key = e.currentTarget.dataset.key;
    let value = isNaN(e.detail.value) ? 0 : e.detail.value;
    this.setData({ [key]: value });
    this.computer();
  },

  /** 计算投资及占比 */
  computer() {
    let arr = [];
    arr.push(this.data.year_val ? parseFloat(this.data.year_val) : 0);
    arr.push(this.data.january_february ? parseFloat(this.data.january_february) : 0);
    arr.push(this.data.march ? parseFloat(this.data.march) : 0);
    arr.push(this.data.april ? parseFloat(this.data.april) : 0);
    arr.push(this.data.may ? parseFloat(this.data.may) : 0);
    arr.push(this.data.june ? parseFloat(this.data.june) : 0);
    arr.push(this.data.july ? parseFloat(this.data.july) : 0);
    arr.push(this.data.august ? parseFloat(this.data.august) : 0);
    arr.push(this.data.september ? parseFloat(this.data.september) : 0);
    arr.push(this.data.october ? parseFloat(this.data.october) : 0);
    arr.push(this.data.november ? parseFloat(this.data.november) : 0);
    arr.push(this.data.december ? parseFloat(this.data.december) : 0);
    let invested = arr.reduce((total, num) => total + num);
    let percentage = (invested / this.data.investment * 100).toFixed(2);
    this.setData({ invested, percentage });
  },

  /** 提交 */
  onSumit() {
    if (this.data.time1 == '请选择日期') {
      app.showFailToast('请选择上会时间');
      return false;
    }
    if (this.data.time2 == '请选择日期') {
      app.showFailToast('请选择签约时间');
      return false;
    }
    if (this.data.remark == '') {
      app.showFailToast('请填写审核情况');
      return false;
    }
    if (this.data.radio == 1) {
      if (this.data.year == '') {
        app.showFailToast('请填写截至年份');
        return false;
      }
    }
    let params = {};
    params.pro_id = this.data.proId;
    params.meeting = this.data.time1;
    params.signing_time = this.data.time2;
    params.remark = this.data.remark;
    params.is_ok = this.data.radio;
    if (this.data.radio == 1) {
      params.year = this.data.year;
      params.year_val = this.data.year_val;
      params.january_february = this.data.january_february;
      params.march = this.data.march;
      params.april = this.data.april;
      params.may = this.data.may;
      params.june = this.data.june;
      params.july = this.data.july;
      params.august = this.data.august;
      params.september = this.data.september;
      params.october = this.data.october;
      params.november = this.data.november;
      params.december = this.data.december;
    }
    // console.log(params)
    app.request('post', '/api/Project/fixedApi', params).then(res => {
      app.showSuccessToast('提交成功');
      this.init();
    }).catch(err => console.log(err));
  },
  //更新企业状况
  bindCondition(e) {
    var condition_val = this.data.condition_val;
    var updatetime = condition_val[e.detail.value].value;
    let params = {
      id: e.currentTarget.dataset.id,
      updatefield: e.currentTarget.dataset.updatefield,
      updatetime: updatetime,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
    }).catch(err => console.log(err));
  },
  //更新培育类别
  bindCultivation(e) {
    var cultivation = this.data.cultivation;
    var updatetime = cultivation[e.detail.value].value;
    let params = {
      id: e.currentTarget.dataset.id,
      updatefield: e.currentTarget.dataset.updatefield,
      updatetime: updatetime,
    };
    app.request('post', '/api/Project/updatetimeApi', params).then(res => {
      this.getBasic();
    }).catch(err => console.log(err));
  },

  //跳转汇报进度视图
  addPlan: function (e) {
    var pro_id = this.data.projectId;
    var type_id = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/addPlan/addPlan?pro_id=' + pro_id + '&type_id=' + type_id
    })
  }
})